package net.orange.framework.controller;

import java.util.ArrayList;
import java.util.Collection;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;

import net.orange.architecture.web.BaseController;
import net.orange.console.schedule.JobStatus;
import net.orange.framework.model.Job;

/**
 * The job managed bean using in JSF MVC modal. it is include the web page
 * content and control the action and page forward direction in the web site.
 */
@ManagedBean(name="job")
@SessionScoped
public class JobController extends BaseController {

	/**
	 * The job's code want to search. 
	 */
	private String sr_code;

	/**
	 * The job's name want to search.
	 */
	private String sr_name;

	/**
	 * The job status selection.
	 */
	private Collection<SelectItem> statuslist;

	/*
	 * (non-Javadoc)
	 * 
	 * @see net.orange.architecture.web.BaseController#getClazz()
	 */
	protected Class getClazz() {
		return Job.class;
	}

	/**
	 * @return Returns the sr_code.
	 */
	public String getSr_code() {
		return sr_code;
	}

	/**
	 * @param sr_code
	 *            The sr_code to set.
	 */
	public void setSr_code(String sr_code) {
		this.sr_code = sr_code;
	}

	/**
	 * @return Returns the sr_name.
	 */
	public String getSr_name() {
		return sr_name;
	}

	/**
	 * @param sr_name
	 *            The sr_name to set.
	 */
	public void setSr_name(String sr_name) {
		this.sr_name = sr_name;
	}

	/**
	 * Return the select item (status type) for selection component.
	 * 
	 * @return the collection of status item (status type).
	 * @throws Exception
	 */
	public Collection getStatuslist() throws Exception {
		if (statuslist == null) {
			statuslist = new ArrayList<SelectItem>();

			SelectItem item1 = new SelectItem();
			item1.setLabel(JobStatus.enabled.name());
			item1.setValue(JobStatus.enabled.name());
			statuslist.add(item1);

			SelectItem item2 = new SelectItem();
			item2.setLabel(JobStatus.disabled.name());
			item2.setValue(JobStatus.disabled.name());
			statuslist.add(item2);
		}
		return statuslist;
	}
}
